import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isNumber from "lodash/isNumber";

var _dec, _dec2, _class;

/**
 * 安全组字段权限 - 侧滑
 * @date: 2019-11-28
 */
import React from 'react';
import { Modal, Table, Button } from 'antd';
import { Bind } from 'lodash-decorators';
import intl from 'utils/intl';
var FieldConfigDrawer = (_dec = Bind(), _dec2 = Bind(), (_class = /*#__PURE__*/function (_React$Component) {
  _inherits(FieldConfigDrawer, _React$Component);

  var _super = _createSuper(FieldConfigDrawer);

  function FieldConfigDrawer(props) {
    var _this;

    _classCallCheck(this, FieldConfigDrawer);

    _this = _super.call(this, props);
    _this.state = {
      dataSource: [],
      pagination: {}
    };
    return _this;
  }

  _createClass(FieldConfigDrawer, [{
    key: "getSnapshotBeforeUpdate",
    value: function getSnapshotBeforeUpdate(prevProps) {
      var _this$props = this.props,
          visible = _this$props.visible,
          _this$props$currentIn = _this$props.currentInterface,
          currentInterface = _this$props$currentIn === void 0 ? {} : _this$props$currentIn;
      var id = currentInterface.id;
      return visible && _isNumber(id) && id !== (prevProps.currentInterface || {}).id;
    }
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate(prevProps, prevState, snapshot) {
      // If we have a snapshot value, we've just added new items.
      // Adjust scroll so these new items don't push the old ones out of view.
      // (snapshot here is the value returned from getSnapshotBeforeUpdate)
      if (snapshot) {
        this.handleFetchFieldConigList();
      }
    }
  }, {
    key: "handleFetchFieldConigList",
    value: function handleFetchFieldConigList() {
      var _this2 = this;

      var _this$props2 = this.props,
          _this$props2$onFetchD = _this$props2.onFetchDetail,
          onFetchDetail = _this$props2$onFetchD === void 0 ? function () {} : _this$props2$onFetchD,
          _this$props2$currentI = _this$props2.currentInterface,
          currentInterface = _this$props2$currentI === void 0 ? {} : _this$props2$currentI;
      var id = currentInterface.id;
      onFetchDetail(id).then(function (_ref) {
        var _ref$dataSource = _ref.dataSource,
            dataSource = _ref$dataSource === void 0 ? [] : _ref$dataSource,
            _ref$pagination = _ref.pagination,
            pagination = _ref$pagination === void 0 ? {} : _ref$pagination;

        _this2.setState({
          dataSource: dataSource,
          pagination: pagination
        });
      });
    }
  }, {
    key: "handleCancel",
    value: function handleCancel() {
      var _this$props$onCancel = this.props.onCancel,
          onCancel = _this$props$onCancel === void 0 ? function () {} : _this$props$onCancel;
      onCancel();
      this.setState({
        dataSource: [],
        pagination: {}
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props3 = this.props,
          _this$props3$visible = _this$props3.visible,
          visible = _this$props3$visible === void 0 ? false : _this$props3$visible,
          loading = _this$props3.loading;
      var _this$state = this.state,
          dataSource = _this$state.dataSource,
          pagination = _this$state.pagination;
      var columns = [{
        title: intl.get('ciam.roleManagement.model.fieldPermission.fieldName').d('字段名称'),
        dataIndex: 'fieldName'
      }, {
        title: intl.get('ciam.roleManagement.model.fieldPermission.fieldType').d('字段类型'),
        dataIndex: 'fieldTypeMeaning'
      }, {
        title: intl.get('ciam.roleManagement.model.fieldPermission.rule').d('权限规则'),
        dataIndex: 'permissionTypeMeaning'
      }, {
        title: intl.get('ciam.roleManagement.model.fieldPermission.desensitize').d('脱敏规则'),
        dataIndex: 'permissionRule'
      }, {
        title: intl.get('ciam.securityGroup.model.securityGroup.remark').d('说明'),
        dataIndex: 'remark'
      }];
      var tableProps = {
        dataSource: dataSource,
        pagination: pagination,
        loading: loading,
        columns: columns,
        bordered: true
      };
      return /*#__PURE__*/React.createElement(Modal, {
        width: 800,
        wrapClassName: "ant-modal-sidebar-right",
        transitionName: "move-right",
        visible: visible,
        title: intl.get('ciam.roleManagement.view.title.fieldPermission').d('接口字段权限配置'),
        onCancel: this.handleCancel,
        footer: /*#__PURE__*/React.createElement(Button, {
          type: "primary",
          onClick: this.handleCancel
        }, intl.get('cpaas.common.button.close').d('关闭'))
      }, /*#__PURE__*/React.createElement(Table, tableProps));
    }
  }]);

  return FieldConfigDrawer;
}(React.Component), (_applyDecoratedDescriptor(_class.prototype, "handleFetchFieldConigList", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "handleFetchFieldConigList"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleCancel", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "handleCancel"), _class.prototype)), _class));
export { FieldConfigDrawer as default };